package xpn.platform.common.exception;

/**
 * 业务异常类，表示发生业务异常
 * 
 * @author duwei 2017-08-27
 */
public class XpnBusinessException extends RuntimeException {
	private static final long serialVersionUID = -6422094954472067966L;

	private Integer errorCode; // 错误代码
	private String message; // 返回给ui的信息，给用户看的，不是给开发者看的
	private Object data; // 错误的一些详细信息，例如：传入的参数列表。

	public XpnBusinessException(Integer code, String message) {
		super(message);

		this.setErrorCode(code);
		this.setMessage(message);
	}

	public XpnBusinessException(Integer code, String message, Object data) {
		super(message);

		this.setErrorCode(code);
		this.setMessage(message);
		this.setData(data);
	}

	public XpnBusinessException(XpnExceptionCodeEnum code) {
		super(code.getErrorMessage());

		this.setErrorCode(code.getErrorCode());
		this.setMessage(code.getErrorMessage());
	}

	public XpnBusinessException(XpnExceptionCodeEnum code, String message) {
		super(message);

		this.setErrorCode(code.getErrorCode());
		this.setMessage(message);
	}

	public XpnBusinessException(XpnExceptionCodeEnum code, Object data) {
		super(code.getErrorMessage());
		this.setErrorCode(code.getErrorCode());
		this.setMessage(code.getErrorMessage());
		this.setData(data);
	}

	public XpnBusinessException(XpnExceptionCodeEnum code, String message, Object data) {
		super(message);
		this.setErrorCode(code.getErrorCode());
		if (message != null) {
            this.setMessage(message);
        } else {
            this.setMessage(code.getErrorMessage());
        }
		this.setData(data);
	}

	public Integer getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(Integer errorCode) {
		this.errorCode = errorCode;
	}

	@Override
    public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
}